package com.acwing.partition12;

import java.io.*;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2022/1/14 9:04
 */
public class AC1137选择最佳线路 {

    private static final int N = 1010, M = 20010, INF = 0x3f3f3f3f;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    private static int n = 0, m = 0, index = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String str = reader.readLine();
            if (str == null || str.isEmpty()) break;
            String[] s = str.split("\\s+");
            n = Integer.parseInt(s[0]);
            m = Integer.parseInt(s[1]);
            int end = Integer.parseInt(s[2]);
            for (int i = 1; i <= n; i++) head[i] = -1;
            index = 0;
            for (int i = 0; i < m; i++) {
                s = reader.readLine().split("\\s+");
                int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
                createEdge(u, v, w);
            }
            int cnt = Integer.parseInt(reader.readLine());
            int[] starts = new int[cnt];
            s = reader.readLine().split("\\s+");
            for (int i = 0; i < cnt; i++) starts[i] = Integer.parseInt(s[i]);
            writer.write(dijkstra(starts, end) + "\n");
        }
        writer.flush();
    }

    private static int dijkstra(int[] starts, int end) {
        int[] dist = new int[n + 1];
        boolean[] visited = new boolean[n + 1];
        for (int i = 1; i <= n; i++) dist[i] = INF;
        PriorityQueue<int[]> heap = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[1], o2[1]));
        for (int i = 0; i < starts.length; i++) {
            dist[starts[i]] = 0;
            heap.add(new int[]{starts[i], 0});
        }
        while (!heap.isEmpty()) {
            int[] pair = heap.poll();
            int u = pair[0];
            if (u == end) return pair[1];
            if (visited[u]) continue;
            visited[u] = true;
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (dist[v] > dist[u] + weight[i]) {
                    dist[v] = dist[u] + weight[i];
                    heap.add(new int[]{v, dist[v]});
                }
            }
        }
        return -1;
    }

    private static void createEdge(int u, int v, int w) {
        element[index] = v;
        next[index] = head[u];
        head[u] = index;
        weight[index++] = w;
    }
}
